package com.yuliang.controller;

import com.yuliang.domain.R;
import com.yuliang.domain.dto.ChangeRoleStatusDto;
import com.yuliang.domain.vo.AddRoleVo;
import com.yuliang.domain.vo.UpdateRoleVo;
import com.yuliang.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/list")
    public R pageList(Integer pageNum,Integer pageSize,String roleName,String status){
        return roleService.pageList(pageNum,pageSize,roleName,status);
    }

    @PutMapping("/changeStatus")
    public R changeRoleStatus(@RequestBody ChangeRoleStatusDto changeRoleStatusDto){
        return roleService.changeRoleStatus(changeRoleStatusDto);
    }

    @PostMapping
    public R addRole(@RequestBody AddRoleVo addRoleVo){
        return roleService.addRole(addRoleVo);
    }

    @GetMapping("/{id}")
    public R getRoleDetail(@PathVariable("id") Long id){
        return roleService.getRoleDetail(id);
    }

    @PutMapping
    public R updateRole(@RequestBody UpdateRoleVo updateRoleVo){
        return roleService.updateRole(updateRoleVo);

    }

    @DeleteMapping("/{id}")
    public R deleteRole(@PathVariable("id") Long id){
        return roleService.deleteRole(id);
    }

    @GetMapping("/listAllRole")
    public R listAllRole(){
        return roleService.listAllRole();
    }
}
